/*
 * @Author: fishroom
 * @Date: 2021-08-22 19:31:48
 * @LastEditTime: 2021-09-04 10:03:02
 * @FilePath: \backstage\src\router\index.js
 */
import Vue from "vue";
import VueRouter from "vue-router";
// import Home from "views/home/Home.vue";
import Main from "views/main/Main.vue";
import TreeViewDetail from "views/background/TreeViewDetail";
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Main",
    component: Main,

    children: [
      {
        path: "/",
        name: "Home",
        component: () => import("views/home/Home.vue"),
        meta: {
          title: "座落后台管理首页"
        }
      },
      {
        path: "/property/:name",
        name: "Property",
        meta: {
          title: "座落资产"
        },
        component: () => import("views/property/Property.vue")
      },
      {
        path: "/map",
        name: "Map",
        meta: {
          title: "地图展示"
        },
        component: () => import("views/map/Map.vue")
      },
      {
        path: "/detailPage/:id",
        name: "DetailPage",
        meta: {
          title: "详情页"
        },
        component: () => import("views/detailPage/DetailPage.vue")
      },
      {
        path: "/login",
        name: "Login",
        meta: {
          title: "登陆页"
        },
        component: () => import("views/login/Login.vue")
      }
    ]
  },
  {
    path: "/background",
    name: "Background",
    meta: {
      title: "后台管理系统"
    },
    component: () => import("views/background/Background.vue"),
    beforeEnter: (to, from, next) => {
      if (localStorage.getItem("token") != undefined) {
        next();
      } else {
        next("/login");
      }
    },
    children: [
      {
        path: "/",
        name: "Index",
        component: () => import("views/background/childsContent/Index.vue"),
        meta: {
          title: "后台管理首页"
        }
      },
      {
        path: "/background/account/super",
        name: "Super",
        component: () =>
          import("views/background/childsContent/account/Super.vue"),
        meta: {
          title: "角色列表"
        }
      },
      {
        path: "/background/account/admin",
        name: "Admin",
        component: () =>
          import("views/background/childsContent/account/Admin.vue")
      },
      {
        path: "/background/account/user",
        name: "User",
        component: () =>
          import("views/background/childsContent/account/User.vue")
      },
      {
        path: "/background/information/basicInformation",
        name: "BasicInformation",
        component: () =>
          import(
            "views/background/childsContent/information/BasicInformation.vue"
          ),
        meta: {
          title: "基本信息"
        }
      },
      //类型信息
      {
        path: "/background/information/detail/barracks",
        name: "Barracks",
        component: () =>
          import(
            "views/background/childsContent/information/detail/Barracks.vue"
          ),
        meta: {
          title: "营房信息"
        }
      },
      {
        path: "/background/information/detail/farm",
        name: "Farm",
        component: () =>
          import("views/background/childsContent/information/detail/Farm.vue"),
        meta: {
          title: "养殖场信息"
        }
      },
      {
        path: "/background/information/detail/history",
        name: "History",
        component: () =>
          import(
            "views/background/childsContent/information/detail/History.vue"
          ),
        meta: {
          title: "历史沿革"
        }
      },
      {
        path: "/background/information/detail/hotel",
        name: "Hotel",
        component: () =>
          import("views/background/childsContent/information/detail/Hotel.vue"),
        meta: {
          title: "酒店信息"
        }
      },
      {
        path: "/background/information/detail/range",
        name: "Range",
        component: () =>
          import("views/background/childsContent/information/detail/Range.vue"),
        meta: {
          title: "靶场信息"
        }
      },
      {
        path: "/background/information/detail/storange",
        name: "Storange",
        component: () =>
          import(
            "views/background/childsContent/information/detail/Storange.vue"
          ),
        meta: {
          title: "仓储信息"
        }
      },
      // 楼栋信息
      {
        path: "/background/information/tower",
        name: "Tower",
        component: () =>
          import("views/background/childsContent/information/Tower.vue"),
        meta: {
          title: "楼栋信息"
        }
      },
      // 设备信息
      {
        path: "/background/information/facility",
        name: "Facility",
        component: () =>
          import("views/background/childsContent/information/Facility.vue"),
        meta: {
          title: "设备信息"
        }
      },
      // 遗留问题信息
      {
        path: "/background/information/leftoverProblem",
        name: "LeftoverProblem",
        component: () =>
          import(
            "views/background/childsContent/information/LeftoverProblem.vue"
          ),
        meta: {
          title: "历史遗留"
        }
      },
      {
        path: "/background/information/elevator",
        name: "Elevator",
        component: () =>
          import("views/background/childsContent/information/Elevator.vue"),
        meta: {
          title: "电梯信息"
        }
      },
      {
        path: "/background/information/project",
        name: "Project",
        component: () =>
          import("views/background/childsContent/information/Project.vue"),
        meta: {
          title: "工程信息"
        }
      },
      {
        path: "/background/childsContent/dictionaries/dictionaries",
        name: "dictionaries",
        component: () =>
          import(
            "views/background/childsContent/dictionaries/DictionariesView.vue"
          ),
        meta: {
          title: "字典查询"
        }
      }
    ]
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

// 前置钩子;
// router.beforeEach((to, from, next) => {
//   if (to.matched.length > 1) {
//     document.title = to.matched[1].meta.title;
//   } else if ((to.matched.length = 1)) {
//     document.title = to.matched[0].meta.title;
//   } else {
//     document.title = "";
//   }
//   next();
// });

export default router;
